package Servlet;

import DAO.CustomerDAO;
import DAO.DAOFactory;
import javabean.Customer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/CustomerManager")
public class CustomerManagerServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CustomerDAO customerDAO = (CustomerDAO) DAOFactory.getCustomerDAOInstance();
        try {
            List<Customer> customerList = customerDAO.getAllCustomer();
            req.setAttribute("customerList", customerList);
            req.getRequestDispatcher("CustomerManager.jsp").forward(req, resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
